package com.coderman.topn.bloomfilter;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

/**
 * @Author fanchunshuai
 * @Date 2019/11/25 14
 * @Description:
 * https://www.cnblogs.com/CodeBear/p/10911177.html
 * https://blog.csdn.net/xinzhongtianxia/article/details/81294922
 *
 *
 *
 * 自实现bloomfilter
 * https://blog.csdn.net/u014653197/article/details/76397037
 */
public class BloomFilterDemo {
    //预计要插入多少数据
    private static int size = 1000000;
    //期望的误判率
    private static double fpp = 0.01f;

    private static BloomFilter<Integer> bloomFilter =BloomFilter.create(Funnels.integerFunnel(),size,fpp);

    public static void main(String[] args) {

        for (int i = 0;i < 1000000;i ++){
            bloomFilter.put(i);
        }
        int count = 0;
        for (int i = 1000000;i < 2000000;i++){
            if(bloomFilter.mightContain(i)){
                count++;
                System.out.println(i +" 误判了.");
            }
        }
        System.out.println("总共的误判数："+count);
    }


}
